#!/bin/bash

# 获取脚本所在目录
SCRIPT_DIR=$(dirname "$0")

SHELL_FOLDER=$(dirname $(readlink -f "$0"))
echo $SHELL_FOLDER




export DRONE_ID=1
export ROS_RECORDER_CONFIG_PATH="$SCRIPT_DIR/config/config.yaml"
LOG_HOME=$HOME/log/uav_$DRONE_ID/rosRecorder
mkdir -p ${LOG_HOME}
export ROS_RECORDER_BAG_PATH="$LOG_HOME"


# 检查配置文件是否存在
if [ ! -f "$ROS_RECORDER_CONFIG_PATH" ]; then
    echo "Config file not found at $CONFIG_FILE. Please ensure it exists."
    exit 1
fi

# 进入二进制文件目录
cd "$SCRIPT_DIR/bin"

# 启动roscore（如果没有运行）
if ! pgrep -x "roscore" > /dev/null
then
    echo "Starting roscore..."
    roscore &
    sleep 5  # 等待 roscore 启动
else
    echo "roscore is already running."
fi

# 启动 rosbag_recorder_node
echo "Starting rosbag_recorder_node..."
./rosbag_recorder_node
